{block name="resources"}
<style type="text/css">
	.refresh-time {color: #B2B2B2;margin-top: 10px;}
	.form-row p {margin:8px 0 0 100px;font-size: 12px;color: #979897;}
	.all-box-item{width:100%;background: #FFFFFF;height: 160px;}
	.all-shop-information{width: 100%;background: white;padding: 15px;box-sizing: border-box;margin-top: 15px;margin-bottom: 30px;}
	.all-shop-information .all-top{display: flex;align-items: center;justify-content: space-between;}
	.all-shop-information .all-top a{font-size: 14px;margin-left: 10px;}
	.all-shop-information .all-top .edit{cursor: pointer;}
	.all-shop-information .all-item{display: flex;align-items: center;}
	.all-shop-information .all-item{margin-bottom: 18px;}
	.all-shop-information .all-item p{width: 140px;text-align: right;font-size: 14px;margin-right: 10px;color: #333;}
	.all-box-item .reason-growth{margin-left: 10px;color: #999;cursor: pointer;}
	.tips-wrap .layui-colla-content li{line-height: 20px;font-size: 13px;}
	.tips-wrap .layui-colla-title{line-height: 24px;height: 28px;font-size: 15px;}
</style>
{/block}
{block name="main"}
<div class="layui-form all-box-item all-shop-information">
		<div class="all-top">
			<div class="title">商家端设置
				<!-- <div class="prompt-block">
					<div class="prompt">
						<i class="iconfont iconwenhao1 required growth"></i>
						<div class="growth-box reason-box reason-growth prompt-box">
							<div class="prompt-con">
								<p>默认</p>
							</div>
						</div>
					</div>
				</div> -->
				<a href="{:addon_url('mobileshop://shop/config/weapp')}" target="_blank" class="text-color">微信小程序设置</a>
			</div>
			<span class="edit text-color" onclick="editOpenMshop()">编辑</span>
		</div>
		<div class="all-content">
			<div class="all-item">
				<p>部署方式：</p>
				<a>
					{if $config.deploy_way eq 'default'}
						默认部署
					{/if}
					
					{if $config.deploy_way eq 'separate'}
						独立部署
					{/if}
				</a>
			</div>
			<div class="all-item">
				<p>商家端域名：</p>
				{if $config.deploy_way eq 'default'}
				<a class="text-color" href="{$root_url}/mshop" target="_blank">{$root_url}/mshop</a>
				{/if}
				{if $config.deploy_way eq 'separate'}
				<a class="text-color" href="{$config.domain_name_mobileshop ?? ''}" target="_blank">{$config.domain_name_mobileshop ?? ''}</a>
				{/if}
			</div>
		</div>
	</div>
{/block}

{block name="script"}
<script type="text/html" id="contentMshop">
	<div class="layui-collapse tips-wrap">
	    <div class="layui-colla-item">
	        <h2 class="layui-colla-title">操作提示</h2>
	        <ul class="layui-colla-content layui-show">
	            <li>为满足不同用户的需求，方便快速搭建手机版商家端，增加以下三种部署方式供其选择，易上手难度递增。</li>
	            <li>（难度：简单）默认部署：无需下载，一键刷新，API接口请求地址默认为当前域名，编译代码存放到mshop文件夹中。</li>
	            <li>（难度：中等）独立部署：下载编译代码包后，放到网站根目录下运行。</li>
	            <li>（难度：较高）源码下载：下载uni-app代码包，可进行二次开发。</li>
	        </ul>
	    </div>
	</div>
	<div class="layui-form form-wrap">
	    <div class="layui-form-item">
	        <label class="layui-form-label">部署方式：</label>
	        <div class="layui-input-block">
	            <input type="radio" name="deploy_way" value="default" lay-filter="deploy_way" title="默认部署" data-desc="无需下载，一键刷新，API接口请求地址为当前域名，编译代码存放到mshop文件夹中" {if $config.deploy_way eq 'default'}checked{/if}/>
	            <input type="radio" name="deploy_way" value="separate" lay-filter="deploy_way" title="独立部署" data-desc="下载编译代码包后，放到网站根目录下运行"  {if $config.deploy_way eq 'separate'}checked{/if}/>
	<!--            {if $is_auth}<input type="radio" name="deploy_way" value="os" lay-filter="deploy_way" title="源码下载" data-desc="下载uni-app代码包，可进行二次开发"/>{/if}-->
	        </div>
	        <div class="word-aux js-desc">
	            {if $config.deploy_way eq 'default'}
	            无需下载，一键刷新，API接口请求地址为当前域名，编译代码存放到mshop文件夹中
	            {else/}
	            下载编译代码包后，放到网站根目录下运行
	            {/if}
	        </div>
	    </div>
	    <div class="deploy-way default {if $config.deploy_way neq 'default'}layui-hide{/if}">
	        <div class="layui-form-item web-url">
	            <label class="layui-form-label">域名地址：</label>
	            <div class="layui-input-block">
					<a href="{$root_url}/mshop" target="_blank" class="text-color">{$root_url}/mshop</a>
	            </div>
	        </div>
	        <div class="form-row" style="margin: 0;">
	           <label class="layui-form-label">部署操作：</label>
	           <button class="layui-btn js-save" onclick="refreshMb()">重新编译</button>
	           <p>以下几种情况，需重新编译</p>
	           <p>在线升级后，如果是默认部署，则需点击重新编译</p>
	           <p>SSL证书变更后，由于http协议变更，则需点击重新编译</p>
	        </div>
	    </div>
	    <div class="deploy-way separate {if $config.deploy_way neq 'separate'}layui-hide{/if}">
	        <div class="layui-form-item">
	            <label class="layui-form-label">商家端域名：</label>
	            <div class="layui-input-block">
	                <input type="text" name="domain" lay-verify="domain" {if $config.deploy_way eq 'separate'}value="{$config['domain_name_mobileshop'] ?? ''}"{/if} autocomplete="off" class="layui-input len-long">
	            </div>
				<div class="word-aux">域名必须以http://或https://为开头</div>
	        </div>
	        <div class="layui-form-item web-url">
	            <label class="layui-form-label">源码下载：</label>
	            <div class="layui-input-block">
	                <button class="layui-btn" lay-submit lay-filter="downloadseparateMb">编译包下载</button>
	                <button class="layui-btn" onclick="window.open(ns.url('mobileshop://shop/config/downloados'));">源码包下载</button>
	            </div>
	            <div class="word-aux">编译包下载之后直接解压到电脑端域名根目录即部署完成。</div>
	            <div class="word-aux">源码包下载之后可进行二次开发，可自行发行进行部署。</div>
	        </div>
	    </div>
	    <div class="form-row all-box-left">
	        <button class="layui-btn js-save" lay-submit lay-filter="mShopSave">保存</button>
	    </div>
	</div>
</script>
<script type="text/javascript">
	var form,mshopPopup;
    layui.use(['form'], function () {
        form = layui.form, repeat_flag = false; //防重复标识;
        $(".js-desc").text($("input[name='deploy_way']:checked").attr("data-desc"));

        form.on('radio(deploy_way)', function(data){
            var value = $(data.elem).val();
            $('.deploy-way').addClass('layui-hide');
            $('.deploy-way.' + value).removeClass('layui-hide');

            var desc = $(data.elem).attr("data-desc");
            $(".js-desc").text(desc);
			refreshArea(mshopPopup)
			
        });

        form.verify({
            domain: function (value, item) {
                var reg = /^((http:\/\/)|(https:\/\/))?\S+$/; //正则表达式验证域名
                if ($("input[name='deploy_way']:checked").val() == "separate") {
                    if (value === '') {
                        return "请输入域名地址";
                    } else if (!(reg.test(value))) {
                        return '请输入正确的域名地址';
                    }
                }
            }
        });

		form.on("submit(downloadseparateMb)",function(data){
			window.open(ns.url('mobileshop://shop/config/downloadcsseparate', {domain: data.field.domain}));
		});

        form.on("submit(mShopSave)", function (data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			$.ajax({
				url: ns.url("mobileshop://shop/config/setMShopDomainName"),
				data: data.field,
				dataType: 'JSON',
				type: 'POST',
				success: function (res) {
					repeat_flag = false;
					layer.msg(res.message);
					if(res.code >= 0){
						location.reload();
					}
				}
			});
        });

    });

    function refreshMb(){
        if (repeat_flag) return false;
        repeat_flag = true;
        $.ajax({
            url: ns.url("mobileshop://shop/config/downloadcsdefault"),
            dataType: 'JSON',
            type: 'POST',
            success: function(res){
                repeat_flag = false;
                layer.msg(res.message);
            }
        });
    }
	
	//打开手机端编辑弹窗
	function editOpenMshop(){
		mshopPopup = layer.open({
			title:'商家端设置',
			type:1,
			area: 'auto',
			maxWidth:700,
			maxHeight:540,
			content:$('#contentMshop').html(),
			success:function(res){
				form.render();
			}
			
		})
	}
</script>
{/block}